<?php namespace Common\Model;
use Hdphp\Model\Model;
class Brand extends Model{
	
	protected $table = "360mall_brand";
	protected $validate = array(
	array("b_name","required","请输入品牌名称",3,3),
	array("b_sort","num:0,40000","排序必须为数字",3,3),
	);
	protected $auto = array(
	array("b_logo","logo","method",3,3)
	);
	//自定义缩略图
	Public function logo(){
	 	//这个为编辑文章写的
	 	//如果隐藏域里面的thumb,直接把隐藏域里面的路径返出		
		if(isset($_POST['b_logo'])){
			return $_POST['b_logo'];
		}
		$path = "Upload/Logo/".date("Ymd");
		$files = Upload::type('jpg,png,txt')->path($path)->size(200000)->make();
		if($files){
		//缩略Image::thumb($file, $outFile, $thumbWidth, $thumbHeight, $thunbType);
		//参数：上传过来的图片路径|存储路径|缩略宽|缩略高|缩略方式
		$logopath = Image::thumb($files[0]['path'],$path."/thumb_".$files[0]['basename'],131,47,5);
		 return $logopath;
		}else{
		//没有文件上传
		 return "";
		}
	}
	public function store(){
		if(!$this->create()) return false;
		$this->add();
		return true;
	}
	//编辑
	public function edit(){
		if(!$this->create()) return false;
		$this->save();
		return true;
	}
}
